]> git.r.bdr.sh - rbdr/map/blame_incremental - Map/Presentation/Base Components/MapRender/MapAxes.swift
Address the lint warnings
[rbdr/map] / Map / Presentation / Base Components / MapRender / MapAxes.swift
... / ...
CommitLineData
1// Copyright (C) 2024 Rubén Beltrán del Río
2
3// This program is free software: you can redistribute it and/or modify
4// it under the terms of the GNU General Public License as published by
5// the Free Software Foundation, either version 3 of the License, or
6// (at your option) any later version.
7
8// This program is distributed in the hope that it will be useful,
9// but WITHOUT ANY WARRANTY; without even the implied warranty of
10// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11// GNU General Public License for more details.
12
13// You should have received a copy of the GNU General Public License
14// along with this program. If not, see https://map.tranquil.systems.
15import SwiftUI
16
17struct MapAxes: View {
18
19 let mapSize: CGSize
20 let lineWidth: CGFloat
21 let evolution: Stage
22 let stages: [CGFloat]
23 let stageHeight = CGFloat(100.0)
24 let padding = CGFloat(5.0)
25
26 var body: some View {
27 ZStack(alignment: .topLeading) {
28
29 // Axis Lines
30 Path { path in
31 path.move(to: CGPoint(x: 0, y: 0))
32 path.addLine(to: CGPoint(x: 0, y: mapSize.height))
33 path.addLine(to: CGPoint(x: mapSize.width, y: mapSize.height))
34 path.move(to: CGPoint(x: mapSize.width, y: mapSize.height))
35 path.closeSubpath()
36 }.stroke(Color.Map.axisColor, lineWidth: lineWidth * 2)
37
38 // Y Labels
39 Text("Visible").font(.Theme.axisLabel).foregroundColor(.Map.labelColor).rotationEffect(
40 Angle(degrees: -90.0)
41 )
42 .offset(CGSize(width: -35.0, height: 0.0))
43 Text("Invisible").font(.Theme.axisLabel).foregroundColor(.Map.labelColor).rotationEffect(
44 Angle(degrees: -90.0)
45 )
46 .offset(CGSize(width: -40.0, height: mapSize.height - 20))
47
48 // X Labels
49
50 Text("Uncharted")
51 .font(.Theme.axisLabel)
52 .foregroundColor(.Map.labelColor)
53 .frame(width: mapSize.width / 4, height: stageHeight / 2.0, alignment: .topLeading)
54 .offset(CGSize(width: 0.0, height: -stageHeight / 4.0))
55 Text("Industrialised")
56 .font(.Theme.axisLabel)
57 .foregroundColor(.Map.labelColor)
58 .frame(width: mapSize.width / 4, height: stageHeight / 2.0, alignment: .topLeading)
59 .offset(CGSize(width: mapSize.width - 100.0, height: -stageHeight / 4.0))
60
61 Text(evolution.i)
62 .font(.Theme.axisLabel)
63 .foregroundColor(.Map.labelColor)
64 .frame(width: w(stages[0]), height: stageHeight, alignment: .topLeading)
65 .offset(CGSize(width: 0.0, height: mapSize.height + padding))
66
67 Text(evolution.ii)
68 .font(.Theme.axisLabel)
69 .foregroundColor(.Map.labelColor)
70 .frame(width: w(stages[1]) - w(stages[0]), height: stageHeight, alignment: .topLeading)
71 .offset(CGSize(width: w(stages[0]), height: mapSize.height + padding))
72
73 Text(evolution.iii)
74 .font(.Theme.axisLabel)
75 .foregroundColor(.Map.labelColor)
76 .frame(width: w(stages[2]) - w(stages[1]), height: stageHeight, alignment: .topLeading)
77 .offset(CGSize(width: w(stages[1]), height: mapSize.height + padding))
78
79 Text(evolution.iv)
80 .font(.Theme.axisLabel)
81 .foregroundColor(.Map.labelColor)
82 .frame(width: mapSize.width - w(stages[2]), height: stageHeight, alignment: .topLeading)
83 .offset(CGSize(width: w(stages[2]), height: mapSize.height + padding))
84 }
85 }
86
87 func w(_ dimension: CGFloat) -> CGFloat {
88 max(0.0, min(mapSize.width, dimension * mapSize.width / 100.0))
89 }
90}
91
92#Preview {
93 MapAxes(
94 mapSize: CGSize(width: 200.0, height: 200.0), lineWidth: CGFloat(1.0),
95 evolution: Stage.stages(.general), stages: [25.0, 50.0, 75.0]
96 ).padding(50.0)
97}